/*
 * @Author: 哈兰德
 * @Description: 抽离出来管理端方法 优化和精简index.vue
 */
import tool from '@/util/tool'
import selfUtil from './util'
import { Message } from 'element-ui'
export default {
  getDefaultImages (num, text) {
    let list = []
    for (let k = 0; k < num; k++) {
      list.push({
        text: text,
        image: '',
        _id: tool.guid(),
        hotAreaList: [],
        uploadTag: false
      })
    }
    return list
  },
  beforeUpload (file) {
    let isImage = file.type.indexOf('image/') !== -1
    let isGif = file.type.indexOf('gif') !== -1
    let isSizeLimit = file.size / 1024 <= 300
    let isSizeLimitGif = file.size / 1024 <= 400
    if (!isImage) {
      Message.error('只能上传图片!')
      return false
    }
    if (!isGif && !isSizeLimit) {
      Message.error('图片大小不能超过300KB!')
      return false
    }
    if (isGif && !isSizeLimitGif) {
      Message.error('图片大小不能超过400KB!')
      return false
    }
    return true
  },
  transferList (item) {
    let list = []
    if (item.id <= 4) {
      list = selfUtil.getDefaultImages(item.num, item.text)
    } else if (item.id === 5) {
      list = [
        ...selfUtil.getDefaultImages(1, '375 x 750'),
        ...selfUtil.getDefaultImages(2, '375 x 375')
      ]
    } else if (item.id === 6) {
      list = [
        ...selfUtil.getDefaultImages(1, '750 x 375'),
        ...selfUtil.getDefaultImages(2, '375 x 375')
      ]
    } else if (item.id === 7) {
      list = [
        ...selfUtil.getDefaultImages(1, '750 x 375'),
        ...selfUtil.getDefaultImages(1, '375 x 375'),
        ...selfUtil.getDefaultImages(2, '188 x 375')
      ]
    }
    else if (item.id === 8) {
      list = [
        ...selfUtil.getDefaultImages(1, '750 x 375'),
        ...selfUtil.getDefaultImages(1, '375 x 375'),
        ...selfUtil.getDefaultImages(2, '188 x 375')
      ]
    }
    return list
  }
}
